#include <bits/stdc++.h>
// 2025/01/19
// tag: 
// Author: Zhang Muen
using namespace std;

class UF
{
public:
    vector<int> parents;
    int cnt;

    UF(int n)
    {
        cnt = n;
        for (int i = 0; i < n; i++)
            parents.push_back(i);
    };

    int find(int i)
    {
        if (parents[i] != i)
            return parents[i] = find(parents[i]);
        return parents[i];
    }

    void un(int i, int j)
    {
        int ri = find(i), rj = find(j);
        if (ri == rj)
            return;
        parents[ri] = rj;
        cnt--;
    }

    int count()
    {
        return cnt;
    }

    bool connected(int p, int q)
    {
        return find(p) == find(q);
    }
};

signed main()
{
    int n, m;
    cin >> n >> m;
    UF uf(n);
    int t, u, v;
    for (int i = 0; i < m; i++){
        cin >> t >> u >> v;
        if (t == 1)
            uf.un(u, v);
        else
            cout << (uf.connected(u, v) ? "Y" : "N") << endl;
    }
    return 0;
}